import pickle

from itpay.utils.redis_client import redis_db_client

USER_PREFIX = "user_{}_{}"
USER_EXPIRE_TIME = 10 * 60


def get_user(mch_id, user_id):
    user = redis_db_client.get(USER_PREFIX.format(mch_id, user_id))
    if user:
        return pickle.loads(user)


def set_user(mch_id, user):
    redis_db_client.setex(
        USER_PREFIX.format(mch_id, user["user_id"]),
        USER_EXPIRE_TIME,
        pickle.dumps(user),
    )
